function check(str) {
	if (str == "") {
		document.getElementById("txtCheck").innerHTML = "";
	}
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	} else {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
			document.getElementById("txtCheck").innerHTML = xmlhttp.responseText;
	};
	xmlhttp.open("GET", "checkUserName.jsp?q=" + str, true);
	xmlhttp.send();
}
function fc1() {
	document.myForm.txtSearch.value = "";
}

function fc2(id) {
	var x = document.getElementById('category');
	x.selectedIndex = id;

	if (id == "") {
		document.getElementById("result").innerHTML = "";
	}
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	} else {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
			document.getElementById("result").innerHTML = xmlhttp.responseText;
	};
	xmlhttp.open("GET", "showProductByCategory.jsp?categoryID=" + id, true);
	xmlhttp.send();

}

function viewCart() {
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	} else {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
			document.getElementById("result").innerHTML = xmlhttp.responseText;
	};
	xmlhttp.open("GET", "cartTest.jsp", true);
	xmlhttp.send();
}
function clearShop() {
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	} else {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
			document.getElementById("result").innerHTML = xmlhttp.responseText;
	};
	xmlhttp.open("GET", "cartTest.jsp?option=clear", true);
	xmlhttp.send();
}
function deleteMovie(movieId) {
	// alert(movieId);
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	} else {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
			document.getElementById("result").innerHTML = xmlhttp.responseText;
	};
	xmlhttp.open("GET", "cartTest.jsp?option=delete&deletemovie=" + movieId,
			true);
	xmlhttp.send();
}

function purchase() {
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	} else {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
			document.getElementById("result").innerHTML = xmlhttp.responseText;
	};
	xmlhttp.open("GET", "purchase.jsp", true);
	xmlhttp.send();
}

function bynow(id, movieID) {
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	} else {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	// xmlhttp.onreadystatechange=function()
	// {
	// if (xmlhttp.readyState==4 && xmlhttp.status==200)
	// document.getElementById("result").innerHTML = xmlhttp.responseText;
	// };

	x = document.getElementById(id);
	var c = confirm("You want to buy this film: ! Are you sure? ");
	if (c == true) {
		alert("Thank you to buy my product");
		xmlhttp.open("GET", "cartTest.jsp?movieID=" + movieID, true);
		xmlhttp.send();
	} else {
		alert("Thanks");
	}
}

function fc6(id, movieID) {
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	} else {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	x = document.getElementById(id);
	y = x.parentNode.parentNode.id;
	var title = document.getElementById(y).getElementsByTagName('h3');
	var c = confirm("You want to buy : " + title[0].innerHTML
			+ "! Are you sure? ");
	if (c == true) {
		alert("Thank you to buy my product");
		xmlhttp.open("GET", "cartTest.jsp?movieID=" + movieID, true);
		xmlhttp.send();
	} else {
		alert("Thanks");
	}
}
function updateCart(f) {
	var formElements = "";
	var formValue="";
	for ( var n = 0; n < f.elements.length; n++) {
		formElements += f.elements[n].name + "~";
		formValue+=f.elements[n].value +"~";
	}
	alert(formElements + "\n" + formValue);
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	} else {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
			document.getElementById("result").innerHTML = xmlhttp.responseText;
	};
	xmlhttp.open("GET", "updateCart.jsp?param="+formElements+"&value="+formValue, true);
	xmlhttp.send();
}

function searchMoive() {
	var str = document.myForm.txtSearch.value;
	// alert(str);
	if (str == "") {
		document.getElementById("result").innerHTML = "";
	}
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	} else {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
			document.getElementById("result").innerHTML = xmlhttp.responseText;
	};
	xmlhttp.open("GET", "searchMovie.jsp?categoryName=" + str, true);
	xmlhttp.send();
}

function showDetail(movieId) {
	// alert(movieId);
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	} else {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
			document.getElementById("result").innerHTML = xmlhttp.responseText;
	};
	xmlhttp.open("GET", "showMovieDetails.jsp?movieID=" + movieId, true);
	xmlhttp.send();
}

function viewOrderDetail(OrdId) {
	// alert(OrdId);
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	} else {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
			document.getElementById("result").innerHTML = xmlhttp.responseText;
	};
	xmlhttp.open("GET", "viewOrderDetail.jsp?ordID=" + OrdId, true);
	xmlhttp.send();
}
function viewHistory() {
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	} else {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
			document.getElementById("result").innerHTML = xmlhttp.responseText;
	};
	xmlhttp.open("GET", "viewHistory.jsp", true);
	xmlhttp.send();
}
